﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWTPASS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWTPASS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTPASS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTPASS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTPASS(dwLocal);
            }
            UpdateWTPASS(dwLocal);
        }
        public void InsertWTPASS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WTPASS(WTPMANDANT, WTPPASSNR, WTPSTAKZ, WTPBEZ, WTPEZ, WTPERSFD, WTPPSCHT, WTPLSCHTW, WTPLSCHTK, WTPGSCHT, WTPANZK, WTPRAPP, WTPGLITY, WTPGLATY, WTPGLARH, WTPGLAANZ, WTPPLITY, WTPPLATY, WTPPLARH, WTPPLAANZ, WTPAENDZL, WTPAENDBEN, WTPAENDDAT, WTPNEUBEN, WTPNEUDAT, WTPFILLER)"
                + "VALUES (:WTPMANDANT, :WTPPASSNR, 'A',:WTPBEZ, ' ', 0, 0, 0, 0, 0, 0, 0, '   ', '   ', 0, 0, '   ', '   ', 0, 0 , 0, '        ', 0, :WTPNEUBEN, :WTPNEUDAT, '                             ')";
            or1.Parameters.Add("WTPMANDANT", OracleType.NVarChar).Value = dwData["WTPMANDANT"].ToString();
            or1.Parameters.Add("WTPPASSNR", OracleType.NVarChar).Value = dwData["WTPPASSNR"].ToString();
            or1.Parameters.Add("WTPBEZ", OracleType.NVarChar).Value = dwData["WTPBEZ"].ToString();
            or1.Parameters.Add("WTPNEUBEN", OracleType.NVarChar).Value = dwData["WTPNEUBEN"].ToString();
            or1.Parameters.Add("WTPNEUDAT", OracleType.NVarChar).Value = dwData["WTPNEUDAT"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteWTPASS(string client, string art)
        {

            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE WTPASS WHERE   "
            + "  WTPMANDANT=:WTPMANDANT AND WTPPASSNR=:WTPPASSNR";
            or1.Parameters.Add("WTPMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("WTPPASSNR", OracleType.NVarChar).Value = art;
            Connect2Proxy(or1);
        }
        public DataSet QueryWTPASS(DataRow dwData, int option = 1)
        {
            DataSet set4Return = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WTPASS WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT *FROM WTPASS WHERE   "
                    + "  WTPMANDANT=:WTPMANDANT AND WTPPASSNR=:WTPPASSNR";
                    or1.Parameters.Add("WTPMANDANT", OracleType.NVarChar).Value = dwData["WTPMANDANT"].ToString();
                    or1.Parameters.Add("WTPPASSNR", OracleType.NVarChar).Value = dwData["WTPPASSNR"].ToString();
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "WTPASS";
            }
            set4Return.Merge(Result);
            return set4Return;
        }
        public void UpdateWTPASS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WTPASS SET "
            + "WTPMANDANT=:WTPMANDANT,"
            + "WTPPASSNR=:WTPPASSNR,"
            + "WTPSTAKZ=:WTPSTAKZ,"
            + "WTPBEZ=:WTPBEZ,"
            + "WTPEZ=:WTPEZ,"
            + "WTPERSFD=:WTPERSFD,"
            + "WTPPSCHT=:WTPPSCHT,"
            + "WTPLSCHTW=:WTPLSCHTW,"
            + "WTPLSCHTK=:WTPLSCHTK,"
            + "WTPGSCHT=:WTPGSCHT,"
            + "WTPANZK=:WTPANZK,"
            + "WTPRAPP=:WTPRAPP,"
            + "WTPGLITY=:WTPGLITY,"
            + "WTPGLATY=:WTPGLATY,"
            + "WTPGLARH=:WTPGLARH,"
            + "WTPGLAANZ=:WTPGLAANZ,"
            + "WTPPLITY=:WTPPLITY,"
            + "WTPPLATY=:WTPPLATY,"
            + "WTPPLARH=:WTPPLARH,"
            + "WTPPLAANZ=:WTPPLAANZ,"
            + "WTPAENDZL=:WTPAENDZL,"
            + "WTPAENDBEN=:WTPAENDBEN,"
            + "WTPAENDDAT=:WTPAENDDAT,"
            + "WTPNEUBEN=:WTPNEUBEN,"
            + "WTPNEUDAT=:WTPNEUDAT,"
            + "WTPFILLER=:WTPFILLER "
            + " WHERE  "
            + "  WTPMANDANT=:WTPMANDANT AND WTPPASSNR=:WTPPASSNR";
            or1.Parameters.Add("WTPMANDANT", OracleType.NVarChar).Value = dwData["WTPMANDANT"].ToString();
            or1.Parameters.Add("WTPPASSNR", OracleType.NVarChar).Value = dwData["WTPPASSNR"].ToString();
            or1.Parameters.Add("WTPSTAKZ", OracleType.NVarChar).Value = dwData["WTPSTAKZ"].ToString();
            or1.Parameters.Add("WTPBEZ", OracleType.NVarChar).Value = dwData["WTPBEZ"].ToString();
            or1.Parameters.Add("WTPEZ", OracleType.NVarChar).Value = dwData["WTPEZ"].ToString();
            or1.Parameters.Add("WTPERSFD", OracleType.NVarChar).Value = dwData["WTPERSFD"].ToString();
            or1.Parameters.Add("WTPPSCHT", OracleType.NVarChar).Value = dwData["WTPPSCHT"].ToString();
            or1.Parameters.Add("WTPLSCHTW", OracleType.NVarChar).Value = dwData["WTPLSCHTW"].ToString();
            or1.Parameters.Add("WTPLSCHTK", OracleType.NVarChar).Value = dwData["WTPLSCHTK"].ToString();
            or1.Parameters.Add("WTPGSCHT", OracleType.NVarChar).Value = dwData["WTPGSCHT"].ToString();
            or1.Parameters.Add("WTPANZK", OracleType.NVarChar).Value = dwData["WTPANZK"].ToString();
            or1.Parameters.Add("WTPRAPP", OracleType.NVarChar).Value = dwData["WTPRAPP"].ToString();
            or1.Parameters.Add("WTPGLITY", OracleType.NVarChar).Value = dwData["WTPGLITY"].ToString();
            or1.Parameters.Add("WTPGLATY", OracleType.NVarChar).Value = dwData["WTPGLATY"].ToString();
            or1.Parameters.Add("WTPGLARH", OracleType.NVarChar).Value = dwData["WTPGLARH"].ToString();
            or1.Parameters.Add("WTPGLAANZ", OracleType.NVarChar).Value = dwData["WTPGLAANZ"].ToString();
            or1.Parameters.Add("WTPPLITY", OracleType.NVarChar).Value = dwData["WTPPLITY"].ToString();
            or1.Parameters.Add("WTPPLATY", OracleType.NVarChar).Value = dwData["WTPPLATY"].ToString();
            or1.Parameters.Add("WTPPLARH", OracleType.NVarChar).Value = dwData["WTPPLARH"].ToString();
            or1.Parameters.Add("WTPPLAANZ", OracleType.NVarChar).Value = dwData["WTPPLAANZ"].ToString();
            or1.Parameters.Add("WTPAENDZL", OracleType.NVarChar).Value = dwData["WTPAENDZL"].ToString();
            or1.Parameters.Add("WTPAENDBEN", OracleType.NVarChar).Value = dwData["WTPAENDBEN"].ToString();
            or1.Parameters.Add("WTPAENDDAT", OracleType.NVarChar).Value = dwData["WTPAENDDAT"].ToString();
            or1.Parameters.Add("WTPNEUBEN", OracleType.NVarChar).Value = dwData["WTPNEUBEN"].ToString();
            or1.Parameters.Add("WTPNEUDAT", OracleType.NVarChar).Value = dwData["WTPNEUDAT"].ToString();
            or1.Parameters.Add("WTPFILLER", OracleType.NVarChar).Value = dwData["WTPFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
